<template>
  <div class="demo">
    <template>
      <div v-if="mode === 'edit'">
        <!-- 图片轮播 -->
        <div v-if="currentDataList && currentDataList.length > 0">
          <div style="width: 100%" v-if="swipeAlign=='top'&&swipeAlign!='hide'">
            <div style="text-align: center">{{ swipeStr }}</div>
          </div>
          <el-carousel
            :style="{ height: verticalHeight }"
            :type="swipeType"
            :direction="verticalVal"
          >
            <el-carousel-item v-for="item in currentDataList" :key="item">
              <img :src="item.url" />
            </el-carousel-item>
          </el-carousel>
          <div style="width: 100%" v-if="swipeAlign=='bottom'&&swipeAlign!='hide'">
            <div style="text-align: center">{{ swipeStr }}</div>
          </div>
        </div>

        <!-- 阴影轮播 -->

        <div v-else>
          <div style="width: 100%" v-if="swipeAlign=='top'&&swipeAlign!='hide'">
            <div style="text-align: center" >{{ swipeStr }}</div>
          </div>
          <el-carousel
            :style="{ height: verticalHeight }"
            :type="swipeType"
            :direction="vertical"
          >
            <el-carousel-item v-for="item in 3" :key="item">
              <h3>{{ item }}</h3>
            </el-carousel-item>
          </el-carousel>
          <div style="width: 100%" v-if="swipeAlign=='bottom'&&swipeAlign!='hide'">
            <div style="text-align: center">{{ swipeStr }}</div>
          </div>
        </div>
      </div>
      <div v-else>{{ value }}</div>
    </template>
  </div>
</template>

<script>
import datasource from "../../mixins/datasource";
export default {
  name: "pm-swipe",
  mixins: [datasource],
  components: {},
  props: {
    mode: {
      default: "edit", // 编辑模式和 edit， 展示模式 view
    },
    readonly: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    vertical: {
      type: Boolean,
      default: false,
    },
    verticalHeight: {
      type: String,
      default: "300px",
    },
    swipeType: {
      type: String,
      default: "",
    },
    swipeNo: {
      type: Number,
      default: "",
    },
    swipeAlign: {
      type: String,
      default: "",
    },
    swipeStr:{
      type: String,
      default: "",
    }
  },
  data() {
    return {
      currentDataList: [],
    };
  },
  computed: {
    verticalVal() {
      return this.vertical ? "vertical" : "horizontal";
    },
  },
  watch: {
    options: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length) {
          this.currentDataList = val.map((item) => {
            return {
              url: item._data.url,
              label: item._data.label,
            };
          });
        }
      },
    },
  },
  created() {},
  mounted() {
    console.log(this.swipeNo, "this");
  },
  methods: {},
};
</script>
<style lang="scss" scoped>
.el-carousel__container {
  border: 2px solid red;
}
.demo {
  width: 100%;
  overflow: hidden;
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    margin: 0;
    text-align: center;
  }

  .el-carousel__item img {
    width: 100%;
    height: 100%;
  }

  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }

  .el-carousel__item:nth-child(2n + 1) {
    background-color: #d3dce6;
  }
}
.el-carousel__container {
  height: auto;
}
</style>
